package com.zhou.imserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

/**
 * Created by zhou on 2016/3/12.
 */
public class MainServer {
    public static ArrayList<Socket>  sockets=new ArrayList<Socket>();
    public static ServerReader serverReader;
    public static ServerWriter serverWriter;
    public static void main(String args[]){
        ServerSocket serverSocket = null;
        try {
            serverSocket = new ServerSocket(8888);
        } catch (IOException e) {
            e.printStackTrace();
        }
            while(true){
                Socket socket = null;
                try {
                    socket = serverSocket.accept();
                    serverReader = new ServerReader(socket.getInputStream());
                    serverWriter = new ServerWriter(socket.getOutputStream());
                    serverReader.start();
                    serverWriter.start();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                sockets.add(socket);
                System.out.println("第"+sockets.size()+"个socket已经链接！");
            }

    }



}
